
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for view_my_profile.
	''' </summary>
	Public Partial Class view_my_profile
		Inherits BaseWebPage
		Protected litFriendsCount As System.Web.UI.WebControls.Literal
		Protected txtStartIndexHidden As System.Web.UI.WebControls.TextBox
		Protected txtFriendsCountHidden As System.Web.UI.WebControls.TextBox
		Protected Linkbutton1 As System.Web.UI.WebControls.LinkButton
		Public blankImagesCount As Integer = 0
		Protected Name As String = ""
		Protected hlChangeLookAndFeel As System.Web.UI.WebControls.HyperLink
		Protected sFriendsCount As String = ""
		Protected sMessagesCount As String = ""
		Protected htPageConstants As New Hashtable()

		Public Function CreateDataSource() As ICollection
			Dim usr As BO.User = LoggedUser
			Dim startIndex As Integer = 0
			Dim endIndex As Integer = startIndex + Constants.MAX_PICTURES_ON_WELCOME_PAGE
			Dim i As Integer
			Dim dt As New DataTable()
			Dim dr As DataRow

			dt.Columns.Add(New DataColumn("ImageURL", GetType(String)))
			dt.Columns.Add(New DataColumn("Name", GetType(String)))
			dt.Columns.Add(New DataColumn("OnlineImg", GetType(String)))
			dt.Columns.Add(New DataColumn("FriendID", GetType(String)))
			Dim temp As UserPicture
			Dim FriendsCount As Integer = usr.DirectFriends.Count
			Dim imagesOnLastRow As Integer = 0
			Dim t As Integer = 0

			Dim ufList As UsersFriends = usr.DirectFriends
			Dim usrDFWithMazFirst As New ArrayList()

			endIndex = Math.Min(endIndex, FriendsCount)
			t = (endIndex - startIndex)
			Math.DivRem(t, Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE, imagesOnLastRow)

			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()

			' maz's user to be on top left
			' maz's user to be the first
			Dim usrMaz As User = Users.GetUserByEmail(Constants.WELCOME_MESSAGE_SENDER)
			'			bool bMaz = false;
			'			if( ufList.Contains(usrMaz.ID) )
			'			{
			'				dr = dt.NewRow();
			'
			'				temp = usrMaz.DefaultPicture;
			'				if(temp != null)
			'				{
			'					dr[0] = Pictures.GetPictureSrcFullURL( temp, true, "../");
			'				}
			'				else
			'				{
			'					dr[0] = "../images/default_thumbnail.gif";
			'				}
			'				dr[1] = getBeginning( HttpUtility.HtmlEncode( usrMaz.Name ), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE);
			'				if(LoggedUsersList.Contains(usrMaz.ID))
			'					dr[2] = "../images/online_status.gif";
			'				else
			'					dr[2] = "../images/spacer.gif"; 
			'				dr[3] = usrMaz.ID;
			'				
			'				dt.Rows.Add(dr);
			'							
			'				if( t == Constants.MAX_PICTURES_ON_WELCOME_PAGE )
			'				{
			'					bMaz = true;
			'					t--;
			'				}
			'			}

			For Each udf As DirectFriend In ufList
				If udf.[Friend].ID = usrMaz.ID Then
					usrDFWithMazFirst.Insert(0, udf)
				Else
					usrDFWithMazFirst.Add(udf)
				End If
			Next

			Dim idx As Integer = 0
			While idx < t
				'				DirectFriend df = (DirectFriend) ufList.GetList()[ idx ];
				'
				'				// maz's user to be the first
				'				if(df.Friend.ID == usrMaz.ID)
				'				{
				'					if( ( t < Constants.MAX_PICTURES_ON_WELCOME_PAGE ) && bMaz )
				'						t++;
				'					continue;
				'				}

				Dim df As DirectFriend = DirectCast(usrDFWithMazFirst(idx), DirectFriend)

				dr = dt.NewRow()
				temp = df.[Friend].DefaultPicture
				If temp <> Nothing Then
					dr(0) = Pictures.GetPictureSrcFullURL(temp, True, "../")
				Else
					dr(0) = "../images/default_thumbnail.gif"
				End If

				dr(1) = getBeginning(HttpUtility.HtmlEncode(df.[Friend].Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)

				If LoggedUsersList.Contains(df.[Friend].ID) Then
					dr(2) = "../images/online_status.gif"
				Else
					dr(2) = "../images/spacer.gif"
					' init according to the friend's online status
				End If
				dr(3) = df.[Friend].ID

				dt.Rows.Add(dr)
				System.Math.Max(System.Threading.Interlocked.Increment(idx),idx - 1)
			End While

			If imagesOnLastRow <> 0 Then
				blankImagesCount = Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE - imagesOnLastRow
				i = imagesOnLastRow
				While i < Constants.MAX_PICTURES_ON_ROW_ON_WELCOME_PAGE
					dr = dt.NewRow()
					'dr[0] = "../images/empty_image.gif";
					dr(0) = "../images/spacer.gif"
					dr(1) = ""
					dr(2) = "../images/spacer.gif"
					dt.Rows.Add(dr)
					System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
				End While
			End If

			Dim dv As New DataView(dt)
			Return dv
		End Function

		Public Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)
			' this.pageTemplate.PageTitle = PageTitles.VIEW_MY_PROFILE_PAGE;

			' This page is no more used, so it redirects to member.aspx
			Response.Redirect(Constants.MEMBERS)

			Dim usr As User = LoggedUser
			If usr = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			Me.initPageTitles(Constants.VIEW_MY_PROFILE, "", Form1, Nothing, htPageConstants)
			Me.initAdvertisements(Form1, Nothing)

			' set new messages count link
			Dim list As ArrayList = Messages.GetUserInboxUnreadMessages(usr.ID, False)
			Dim cnt As Integer = list.Count
			If cnt = 0 Then
				hlMessages.Visible = False
			Else
				hlMessages.Text = "<font class='all_friends'>" + cnt + "</font> New Message"
				If cnt > 1 Then
					hlMessages.Text += "s"
				End If
				hlMessages.Text += "<br>"
			End If

			hlEditFriends.NavigateUrl = "../" + Constants.SEE_ALL_FRIENDS + "?action=" + Constants.SEE_ALL_FRIENDS_EDIT_ACTION
			hlEditFriendsComments.NavigateUrl = "../" + Constants.FRIENDS_COMMENTS_PAGE + "?action=" + Constants.FRIENDS_COMMENTS_EDIT_ACTION

			' set About Me							
			lblAboutMe.Text = Me.GetPageConstText(htPageConstants, "CONST_About_TEXT")
			lblAboutMe.Font.Bold = True
			lblAboutMeValue.Text += usr.AboutMe + "<br><br>"

			' set Like to Meet
			lblMeet.Text = Me.GetPageConstText(htPageConstants, "CONST_LikeToMeet_TEXT")
			lblMeet.Font.Bold = True
			lblMeetValue.Text = usr.LookingFor

			Dim isSongEntered As Boolean = False
			' set Live Music
			If usr.SongURL1 <> Nothing AndAlso usr.SongURL1 <> "" Then
				If usr.SongURLName1 <> Nothing AndAlso usr.SongURLName1 <> "" Then
					hlSongName1.Text = getBeginning(HttpUtility.HtmlEncode(usr.SongURLName1), Constants.NAME_MAX_VISIBLE_CHARS) + "<br><br>"
				Else
					hlSongName1.Text = getBeginning(HttpUtility.HtmlEncode(usr.SongURL1), Constants.NAME_MAX_VISIBLE_CHARS) + "<br><br>"
				End If

				hlSongName1.CssClass = "blue"
				hlSongName1.Attributes.Add("href", "#song")
				hlSongName1.Attributes.Add("onclick", Me.constructMusicURL(usr.SongURL1))
				isSongEntered = True
			End If
			If usr.SongURL2 <> "" AndAlso usr.SongURL2 <> Nothing Then
				If usr.SongURLName2 <> Nothing AndAlso usr.SongURLName2 <> "" Then
					hlSongName2.Text = getBeginning(HttpUtility.HtmlEncode(usr.SongURLName2), Constants.NAME_MAX_VISIBLE_CHARS) + "<br><br>"
				Else
					hlSongName2.Text = getBeginning(HttpUtility.HtmlEncode(usr.SongURL2), Constants.NAME_MAX_VISIBLE_CHARS) + "<br><br>"
				End If

				hlSongName2.CssClass = "blue"
				hlSongName2.Attributes.Add("href", "#song")
				hlSongName2.Attributes.Add("onclick", Me.constructMusicURL(usr.SongURL2))
				isSongEntered = True
			End If
			If usr.SongURL3 <> "" AndAlso usr.SongURL3 <> Nothing Then
				If usr.SongURLName3 <> Nothing AndAlso usr.SongURLName3 <> "" Then
					hlSongName3.Text = getBeginning(HttpUtility.HtmlEncode(usr.SongURLName3), Constants.NAME_MAX_VISIBLE_CHARS)
				Else
					hlSongName3.Text = getBeginning(HttpUtility.HtmlEncode(usr.SongURL3), Constants.NAME_MAX_VISIBLE_CHARS)
				End If

				hlSongName3.CssClass = "blue"
				hlSongName3.Attributes.Add("href", "#song")
				hlSongName3.Attributes.Add("onclick", Me.constructMusicURL(usr.SongURL3))
				isSongEntered = True
			End If

			trSongs.Visible = isSongEntered

			' init user template
			Dim userTemplate As BO.Template = usr.Template
			Me.pageTemplate.wavFile = InitWAVFileURL(usr.WAVURL)
			Me.pageTemplate.bgImage = InitBGImage(usr.BGImageURL)

			'init awaiting confirmation link

			Dim invUsers As UserInvitations = usr.PendingInvitations
			If invUsers.Count > 0 Then
				hlViewConfirmation.NavigateUrl = "../" + Constants.VIEW_AWAITING_CONFIRMATION
				hlViewConfirmation.Text = (Me.GetPageConstText(htPageConstants, "CONST_ViewAwaiting_TEXT")).Replace("[PARAM]", invUsers.Count.ToString())
				hlViewConfirmation.Visible = True
			End If

			If userTemplate <> Nothing AndAlso cssFileName <> Nothing Then
				cssFileName = userTemplate.CSSFileName
				'set with DB value: cssFileName = Templates.getTemplateByID(themeID).CSSFileName;
				pageTemplate.StrStyle = Me.InitStyle(cssFileName)
			End If

			' init default photo
			If usr.DefaultPicture <> Nothing Then
				imgPhoto.ImageUrl = Pictures.GetPictureLargeThumbnailSrcFullURL(usr.DefaultPicture, "../")
			Else
				imgPhoto.ImageUrl = Constants.DEFAULT_THUMBNAIL_IMAGE_URL
			End If

			' init photos in album
			Dim pics As ArrayList = usr.GetPictures()
			hlPhotosInAlbum.Text = "<font class='bulletin_orange'>" + pics.Count.ToString() + "</font>" + " Photo"
			If pics.Count <> 1 Then
				hlPhotosInAlbum.Text += "s"
			End If
			hlPhotosInAlbum.Text += " in Album"
			hlPhotosInAlbum.NavigateUrl = "../" + Constants.UPLOAD_PHOTO

			sFriendsCount = usr.DirectFriends.Count.ToString()
			hlEditComments.NavigateUrl = "../" + Constants.FRIENDS_COMMENTS_PAGE + "?action=" + Constants.FRIENDS_COMMENTS_EDIT_ACTION
			Name = usr.Name

			' init "No comments" label
			Dim NewComments As ArrayList = usr.NewComments
			Dim ApprovedComments As ArrayList = usr.Comments

			If NewComments.Count = 0 AndAlso ApprovedComments.Count = 0 Then
				dgMessages.Visible = False
				lblNoComments.Visible = True
				hlEditComments.Visible = False
			End If

			' init user details table

			' set age
			Dim lblAgeValue As New Label()
			Dim lblAge As New Label()
			lblAge.Text = Me.GetPageConstText(htPageConstants, "CONST_Age_TEXT")
			lblAge.Font.Bold = True
			Dim age As TimeSpan = DateTime.Today - usr.BirthDay

			Dim ageYears As Double = (age.Days / 365)
			lblAgeValue.Text = (Convert.ToInt32(ageYears)).ToString()

			addTableRow(lblAge, lblAgeValue)

			'set gender
			Dim lblGenderValue As New Label()
			Dim lblGender As New Label()
			lblGender.Text = Me.GetPageConstText(htPageConstants, "CONST_Gender_TEXT")
			lblGender.Font.Bold = True
			Dim gender As Integer = usr.Gender
			If gender = 1 Then
				lblGenderValue.Text = Me.GetPageConstText(htPageConstants, "CONST_Male_TEXT")
			End If
			If gender = 2 Then
				lblGenderValue.Text = Me.GetPageConstText(htPageConstants, "CONST_Female_TEXT")
			End If

			addTableRow(lblGender, lblGenderValue)

			'set status
			Dim lblStatusValue As New Label()
			Dim lblStatus As New Label()
			lblStatus.Text = Me.GetPageConstText(htPageConstants, "CONST_Status_TEXT")
			lblStatus.Font.Bold = True
			If usr.MaritalStatus <> -1 Then
				lblStatusValue.Text = Constants.ARR_STATUS(usr.MaritalStatus)
			Else
				lblStatusValue.Text = ""
			End If

			addTableRow(lblStatus, lblStatusValue)

			' set Country
			Dim lblCountryValue As New Label()
			Dim lblCountry As New Label()
			lblCountry.Text = Me.GetPageConstText(htPageConstants, "CONST_Country_TEXT")
			lblCountry.Font.Bold = True
			If usr.CountryID = -1 Then
				lblCountryValue.Text = ""
			Else
				lblCountryValue.Text = "<a href='" + Constants.BROWSE + "?" + Constants.COUNTRY_PARAM + "=" + usr.CountryID + "'>" + Constants.COUNTRIES.GetCountryByID(usr.CountryID).Name + "</a>"
			End If

			addTableRow(lblCountry, lblCountryValue)

			'set City
			Dim lblCity As New Label()
			Dim lblCityValue As New Label()
			lblCity.Text = Me.GetPageConstText(htPageConstants, "CONST_City_TEXT")
			lblCity.Font.Bold = True
			If (usr.ZipCode <> "") AndAlso (usr.ZipCode <> Nothing) AndAlso (usr.City <> Nothing) AndAlso (usr.City <> "") Then
				lblCityValue.Text = usr.ZipCode + ", "
			End If
			If usr.City <> Nothing Then
				If isHTML(usr.City) Then
					lblCityValue.Font.Bold = False
					lblCityValue.Text = usr.City
				Else
					lblCityValue.Text += "<a href='" + Constants.BROWSE + "?" + Constants.CITY_PARAM + "=" + usr.City + "'>" + usr.City + "</a>"
				End If
			End If
			addTableRow(lblCity, lblCityValue)

			'set Place of Birth
			Dim lblPlaceOfBirthValue As New Label()
			Dim lblPlaceOfBirth As New Label()
			lblPlaceOfBirth.Text = Me.GetPageConstText(htPageConstants, "CONST_PlaceBirth_TEXT")
			lblPlaceOfBirth.Font.Bold = True
			If usr.PlaceOfBirth <> Nothing Then
				If isHTML(usr.PlaceOfBirth) Then
					lblPlaceOfBirthValue.Font.Bold = False
					lblPlaceOfBirthValue.Text = usr.PlaceOfBirth
				Else
					lblPlaceOfBirthValue.Text = "<a href='" + Constants.BROWSE + "?" + Constants.CITY_PARAM + "=" + usr.PlaceOfBirth + "'>" + usr.PlaceOfBirth + "</a>"
				End If
			Else
				lblPlaceOfBirthValue.Text = "&nbsp;"
			End If

			addTableRow(lblPlaceOfBirth, lblPlaceOfBirthValue)

			' set Interests
			Dim lblInterestsValue As New Label()
			Dim lblInterests As New Label()
			lblInterests.Text = Me.GetPageConstText(htPageConstants, "CONST_Interests_TEXT")
			lblInterests.Font.Bold = True
			If usr.Interests <> Nothing Then
				If isHTML(usr.Interests) Then
					lblInterestsValue.Text = usr.Interests
				Else
					Dim arrInterests As String() = usr.Interests.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrInterests.Length
						lblInterestsValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.INTEREST_PARAM + "=" + arrInterests(i).Trim() + "'>" + arrInterests(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblInterestsValue.Text = lblInterestsValue.Text.Substring(0, lblInterestsValue.Text.Length - 2)
				End If
			Else
				lblInterestsValue.Text = "&nbsp;"
			End If

			addTableRow(lblInterests, lblInterestsValue)

			'set Occupation	
			Dim lblOccupationValue As New Label()
			Dim lblOccupation As New Label()
			lblOccupation.Text = Me.GetPageConstText(htPageConstants, "CONST_Occupation_TEXT")
			lblOccupation.Font.Bold = True
			If usr.Occupation <> Nothing Then
				If isHTML(usr.Occupation) Then
					lblOccupationValue.Text = usr.Occupation
				Else
					lblOccupationValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.OCCUPATION_PARAM + "=" + usr.Occupation + "'>" + usr.Occupation + "</a>"
				End If
			Else
				lblOccupationValue.Text = "&nbsp;"
			End If

			addTableRow(lblOccupation, lblOccupationValue)

			If usr.Affiliations <> "" AndAlso usr.Affiliations <> Nothing Then
				Dim lblAffiliationsValue As New Label()
				Dim lblAffiliations As New Label()
				lblAffiliations.Text = Me.GetPageConstText(htPageConstants, "CONST_Affiliations_TEXT")
				lblAffiliations.Font.Bold = True

				If isHTML(usr.Affiliations) Then
					lblAffiliationsValue.Text = usr.Affiliations
				Else
					Dim arrAffiliations As String() = usr.Affiliations.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrAffiliations.Length
						lblAffiliationsValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.AFFILIATIONS_PARAM + "=" + arrAffiliations(i) + "'>" + arrAffiliations(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While

					lblAffiliationsValue.Text = lblAffiliationsValue.Text.Substring(0, lblAffiliationsValue.Text.Length - 2)
				End If

				addTableRow(lblAffiliations, lblAffiliationsValue)
			End If

			If usr.Companies <> "" AndAlso usr.Companies <> Nothing Then
				Dim lblCompanies As New Label()
				Dim lblCompaniesValue As New Label()
				lblCompanies.Text = Me.GetPageConstText(htPageConstants, "CONST_Companies_TEXT")
				lblCompanies.Font.Bold = True

				If isHTML(usr.Companies) Then
					lblCompaniesValue.Text = usr.Companies
				Else
					Dim arrCompanies As String() = usr.Companies.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrCompanies.Length
						lblCompaniesValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.COMPANIES_PARAM + "=" + arrCompanies(i) + "'>" + arrCompanies(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblCompaniesValue.Text = lblCompaniesValue.Text.Substring(0, lblCompaniesValue.Text.Length - 2)
				End If
				addTableRow(lblCompanies, lblCompaniesValue)
			End If

			If usr.Schools <> "" AndAlso usr.Schools <> Nothing Then
				Dim lblSchools As New Label()
				Dim lblSchoolsValue As New Label()
				lblSchools.Text = Me.GetPageConstText(htPageConstants, "CONST_Schools_TEXT")
				lblSchools.Font.Bold = True

				If isHTML(usr.Schools) Then
					lblSchoolsValue.Text = usr.Schools
				Else
					Dim arrSchools As String() = usr.Schools.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrSchools.Length
						lblSchoolsValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.SCHOOLS_PARAM + "=" + arrSchools(i) + "'>" + arrSchools(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblSchoolsValue.Text = lblSchoolsValue.Text.Substring(0, lblSchoolsValue.Text.Length - 2)
				End If
				addTableRow(lblSchools, lblSchoolsValue)
			End If

			If usr.ImageURL <> "" AndAlso usr.ImageURL <> Nothing Then

				Dim lblFavImage As New Label()
				Dim hlFavImageURL As New HyperLink()
				lblFavImage.Text = Me.GetPageConstText(htPageConstants, "CONST_SeeImage_TEXT")
				lblFavImage.Font.Bold = True

				'hlFavImageURL.NavigateUrl = usr.ImageURL;
				'hlFavImageURL.Text = usr.ImageURL;
				If usr.ImageURLName <> Nothing AndAlso usr.ImageURLName <> "" Then
					hlFavImageURL.Text = usr.ImageURLName
				End If

				'hlFavImageURL.Target = "_blank";
				hlFavImageURL.Attributes.Add("href", "#")
				hlFavImageURL.Attributes.Add("onclick", Me.constructImageURL(usr.ImageURL))

				addTableRow(lblFavImage, hlFavImageURL)
			End If

			If usr.Music <> "" AndAlso usr.Music <> Nothing Then
				Dim lblFavMusic As New Label()
				Dim lblFavMusicValue As New Label()
				lblFavMusic.Text = Me.GetPageConstText(htPageConstants, "CONST_FavouriteMusic_TEXT")
				lblFavMusic.Font.Bold = True

				If isHTML(usr.Music) Then
					lblFavMusicValue.Text = usr.Music
				Else
					Dim arrMusic As String() = usr.Music.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrMusic.Length
						lblFavMusicValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.MUSIC_PARAM + "=" + arrMusic(i) + "'>" + arrMusic(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblFavMusicValue.Text = lblFavMusicValue.Text.Substring(0, lblFavMusicValue.Text.Length - 2)
				End If
				addTableRow(lblFavMusic, lblFavMusicValue)
			End If

			If usr.Books <> "" AndAlso usr.Books <> Nothing Then
				Dim lblFavBooks As New Label()
				Dim lblFavBooksValue As New Label()
				lblFavBooks.Text = Me.GetPageConstText(htPageConstants, "CONST_FavouriteBooks_TEXT")
				lblFavBooks.Font.Bold = True

				If isHTML(usr.Books) Then
					lblFavBooksValue.Text = usr.Books
				Else
					Dim arrBooks As String() = usr.Books.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrBooks.Length
						lblFavBooksValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.BOOKS_PARAM + "=" + arrBooks(i) + "'>" + arrBooks(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblFavBooksValue.Text = lblFavBooksValue.Text.Substring(0, lblFavBooksValue.Text.Length - 2)
				End If
				addTableRow(lblFavBooks, lblFavBooksValue)
			End If

			If usr.TV <> "" AndAlso usr.TV <> Nothing Then
				Dim lblFavTV As New Label()
				Dim lblFavTVValue As New Label()
				lblFavTV.Text = Me.GetPageConstText(htPageConstants, "CONST_FavouriteTVShows_TEXT")
				lblFavTV.Font.Bold = True

				If isHTML(usr.TV) Then
					lblFavTVValue.Text = usr.TV
				Else
					Dim arrTVs As String() = usr.TV.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrTVs.Length
						lblFavTVValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.TV_PARAM + "=" + arrTVs(i) + "'>" + arrTVs(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblFavTVValue.Text = lblFavTVValue.Text.Substring(0, lblFavTVValue.Text.Length - 2)
				End If
				addTableRow(lblFavTV, lblFavTVValue)
			End If

			If usr.Movies <> "" AndAlso usr.Movies <> Nothing Then

				Dim lblFavMovies As New Label()
				Dim lblFavMoviesValue As New Label()
				lblFavMovies.Text = Me.GetPageConstText(htPageConstants, "CONST_FavouriteMovies_TEXT")
				lblFavMovies.Font.Bold = True

				If isHTML(usr.Movies) Then
					lblFavMoviesValue.Text = usr.Movies
				Else
					Dim arrMovies As String() = usr.Movies.Split(","C, ";"C)
					Dim i As Integer = 0
					While i < arrMovies.Length
						lblFavMoviesValue.Text += "<a href='" + Constants.SEARCH + "?" + Constants.MOVIES_PARAM + "=" + arrMovies(i) + "'>" + arrMovies(i) + "</a>, "
						System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
					End While
					lblFavMoviesValue.Text = lblFavMoviesValue.Text.Substring(0, lblFavMoviesValue.Text.Length - 2)
				End If
				addTableRow(lblFavMovies, lblFavMoviesValue)
			End If

			If Not IsPostBack Then
				BindList()
				BindGrid()
			End If

			hlViewMoreComments.NavigateUrl = "../" + Constants.FRIENDS_COMMENTS_PAGE
			If usr.Comments.Count <= Constants.COMMENTS_ON_PROFILE_PAGE Then
				hlViewMoreComments.Visible = False
			End If

		End Sub

		Private Sub addTableRow(ByVal ctlName As Control, ByVal ctlValue As Control)
			Dim tr As New TableRow()
			Dim td1 As New TableCell()
			Dim td2 As New TableCell()

			td1.Controls.Add(ctlName)
			td2.Controls.Add(ctlValue)
			td1.Width = 100
			td2.Width = 210
			td1.CssClass = "clear"
			td2.CssClass = "clear"
			tr.Cells.Add(td1)
			tr.Cells.Add(td2)

			tblUserDetails.Rows.Add(tr)
		End Sub

		Public Sub BindList()
			dlAllFriends.DataSource = CreateDataSource()
			dlAllFriends.DataBind()

			Dim itemsCount As Integer = dlAllFriends.Items.Count
			Dim blankImageIndex As Integer = itemsCount - blankImagesCount
			Dim i As Integer = 0
			i = blankImageIndex
			While i < itemsCount
				(DirectCast(dlAllFriends.Items(i).FindControl("lbName"), System.Web.UI.WebControls.LinkButton)).CssClass = "empty_image"
				(DirectCast(dlAllFriends.Items(i).FindControl("imgFriend"), System.Web.UI.WebControls.Image)).CssClass = "empty_image"
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While
		End Sub

		Protected Function CreateDataSourceForGrid() As ICollection
			Dim startIndex As Integer = 0
			Dim endIndex As Integer = startIndex + Constants.COMMENTS_ON_PROFILE_PAGE

			Dim usr As User = LoggedUser
			Dim dt As New DataTable()
			Dim curCommentDate As DateTime
			Dim LoggedUsersList As ArrayList = Common.Utils.GetLoggedUsersIDs()

			' List user's comments

			Dim dr As DataRow
			dt.Columns.Add(New DataColumn("SenderID", GetType(Integer)))
			dt.Columns.Add(New DataColumn("SenderName", GetType(String)))
			dt.Columns.Add(New DataColumn("SenderImageURL", GetType(String)))
			dt.Columns.Add(New DataColumn("MemberURL", GetType(String)))
			dt.Columns.Add(New DataColumn("Date", GetType(String)))
			dt.Columns.Add(New DataColumn("Time", GetType(String)))
			dt.Columns.Add(New DataColumn("Comment", GetType(String)))
			dt.Columns.Add(New DataColumn("CommentID", GetType(String)))
			dt.Columns.Add(New DataColumn("ButtonsVisibility", GetType(Boolean)))
			dt.Columns.Add(New DataColumn("SenderNameFull", GetType(String)))
			dt.Columns.Add(New DataColumn("OnlineImg", GetType(String)))

			Dim newCommentList As ArrayList, approvedCommentList As ArrayList, allComments As ArrayList
			allComments = New ArrayList()
			newCommentList = usr.NewNotAcceptedComments
			'usr.NewComments;			
			approvedCommentList = usr.Comments
			If usr.ID = LoggedUser.ID Then
				allComments = newCommentList
			End If
			Dim i As Integer = 0
			While i < approvedCommentList.Count
				allComments.Add(approvedCommentList(i))
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While

			endIndex = Math.Min(allComments.Count, endIndex)

			Dim temp As UserPicture
			Dim curSender As User
			Dim usrComment As UserComment
			Dim i As Integer = startIndex
			While i < endIndex
				' List user's NEW comments
				dr = dt.NewRow()
				usrComment = DirectCast(allComments(i), UserComment)
				curCommentDate = usrComment.[Date]
				curSender = Users.GetUserByID(usrComment.PostedByUserID)

				dr(0) = usrComment.PostedByUserID
				dr(1) = getBeginning(HttpUtility.HtmlEncode(curSender.Name), Constants.MAX_NAME_LENGTH_ABOVE_IMAGE)
				dr(9) = curSender.Name
				temp = curSender.DefaultPicture
				If temp <> Nothing Then
					dr(2) = Pictures.GetPictureSrcFullURL(temp, True, "../")
				Else
					dr(2) = Constants.DEFAULT_THUMBNAIL_IMAGE_URL
				End If
				dr(3) = "../" + Constants.MEMBERS + "?id=" + usrComment.PostedByUserID
				dr(4) = curCommentDate.DayOfWeek + ", " + Constants.MONTHS(curCommentDate.Month - 1) + " " + curCommentDate.Day + ", " + curCommentDate.Year
				dr(5) = curCommentDate.ToShortTimeString()
				dr(6) = usrComment.Comment
				dr(7) = usrComment.ID
				If usrComment.CommentStatus = UserComment.Status.ucsNew Then
					dr(8) = True
				Else
					dr(8) = False
				End If
				If LoggedUsersList.Contains(usrComment.PostedByUserID) Then
					dr(10) = "../images/online_status.gif"
				Else
					dr(10) = "../images/spacer.gif"
				End If

				dt.Rows.Add(dr)
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While

			Dim dv As New DataView(dt)
			Return dv
		End Function
		Protected Sub BindGrid()
			dgMessages.DataSource = CreateDataSourceForGrid()
			dgMessages.DataBind()
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.dlAllFriends.ItemCommand, AddressOf Me.dlAllFriends_ItemCommand
			AddHandler Me.dgMessages.ItemCommand, AddressOf Me.dgMessages_ItemCommand

		End Sub
#End Region

		Protected Sub lbEditFriendsWithImage_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Response.Redirect(Constants.SEE_ALL_FRIENDS + "?action=" + Constants.SEE_ALL_FRIENDS_EDIT_ACTION)
		End Sub

		Private Sub dgMessages_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
			Dim usr As User = LoggedUser
			Dim lbPushed As LinkButton = DirectCast(e.CommandSource, LinkButton)
			Dim cmd As String = e.CommandName

			Select Case cmd
				Case "Reject"
					' reject/remove comment
					usr.RemoveComment(Convert.ToInt32(e.CommandArgument))
					Exit Select
				Case "Approve"
					'approve comment
					usr.ApproveComment(Convert.ToInt32(e.CommandArgument))
					Exit Select
			End Select
			BindGrid()
		End Sub
		Private Sub dlAllFriends_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs)
			Dim src As Object = e.CommandSource
			Dim srcType As String = src.[GetType]().ToString()
			Dim cmd As String = e.CommandName
			Dim arg As String = ""
			If srcType.Equals("System.Web.UI.WebControls.ImageButton") Then
				arg = (DirectCast(src, ImageButton)).CommandArgument
			Else
				arg = (DirectCast(src, LinkButton)).CommandArgument
			End If
			Select Case cmd
				Case "MemberRedirect"
					Response.Redirect(Constants.MEMBERS + "?id=" + e.CommandArgument)
					Exit Select
			End Select
		End Sub

		Protected Sub lbAddFriends_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			Response.Redirect(Constants.INVITE_FRIENDS_PAGE)
		End Sub

		====================
		' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
		Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
			Get
				Return Migrated_Form1
			End Get
		End Property
		'set { Migrated_Form1 = value; }
	End Class
End Namespace






